package test.fun;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;
import java.util.ArrayList;

import static test.fun.GetConnet.connection;

/**
 * ClassName: DeleteFun
 * Package: test.fun
 * Description:
 *            TODO  删除数据
 * @Author ChenJun
 * @Create 2023/4/23 9:28
 * @Version 1.0
 */
public class DeleteFun {
    //TODO 删除数据
    public static void deleteDate(String tableName, String rowKey, String cf, String column) throws IOException {

        //获取表名
        Table table = connection.getTable(TableName.valueOf(tableName));

        //创建Delete对象
        Delete delete = new Delete(rowKey.getBytes());
        Delete delete1 = new Delete("1003".getBytes());

        //指定列族
//        delete.addFamily(cf.getBytes());

        //指定到列
//        delete.addColumn(cf.getBytes(),column.getBytes()); //删除指定列的最大版本(单个版本)
//        delete.addColumns(cf.getBytes(),column.getBytes());//删除指定列的所有版本(多个版本)
        ArrayList<Delete> deletes = new ArrayList<>();
        deletes.add(delete);
        deletes.add(delete1);

        //执行删除
        table.delete(deletes);

        //关闭表对象
        table.close();
    }
}
